package cn.juque.lucenecandy.config;

import cn.juque.lucenecandy.core.handlers.EntityMetaObjectHandler;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ComponentScans;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.unit.DataSize;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.servlet.MultipartConfigElement;

/**
 * @author juque
 * @version 1.0.0
 * <ul>
 *     <li>LuceneCandyMvcConfig</li>
 * </ul>
 * @date 2023-12-26
 **/
@Configuration
@ComponentScans(value = {@ComponentScan("cn.hutool.extra.spring")})
public class LuceneCandyMvcConfig implements WebMvcConfigurer {

    @Bean
    public MultipartConfigElement multipartConfigElement() {
        MultipartConfigFactory factory = new MultipartConfigFactory();
        //单个文件大小200mb
        factory.setMaxFileSize(DataSize.ofMegabytes(10));
        //设置总上传数据大小1GB
        factory.setMaxRequestSize(DataSize.ofMegabytes(50));

        return factory.createMultipartConfig();
    }

    @Bean
    public EntityMetaObjectHandler entityMetaObjectHandler() {
        return new EntityMetaObjectHandler();
    }
}
